<?php

namespace app\admin\model\jdy;

use think\Model;

class Smallcategory extends Model
{
    // 表名
    protected $name = 'jdy_smallcategory';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'ignore_duration_time_text'
    ];




    public function getStatusList()
    {
        return ['1' => __('啟用'),'0' => __('不啟用')];
    }

    public function getIgnoreDurationTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ignore_duration_time']) ? $data['ignore_duration_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setIgnoreDurationTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function bigcategory()
    {
        return $this->belongsTo('Bigcategory', 'bigcategory_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
